package com.infoblazer.jimql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * User: Dave
 * Date: Nov 18, 2010
 * Time: 10:31:10 PM
 *
 */
public class DerbyJimql implements JimqlConnection {
     public Connection buildConnection(ThreadLocal<Connection> connectionThreadLocal){
       Connection conn = null;
        try {
              conn = DriverManager.getConnection("jdbc:derby:memory:jimql;create=true");
            
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
          return conn;
    }


    public void dropIfExists(Connection conn ,String tableName) throws SQLException {
         Statement st = null;
         try {
            st = conn.createStatement();
            StringBuilder sb = new StringBuilder();
            sb.append("DROP TABLE ").append(tableName);
            st.execute(sb.toString());
            }
         catch (SQLException ok) {

            }
        finally {
             st.close();
         }
    }
}
